/* Primary functionality for the Financial Chart Gadget. */
var RiseVision = RiseVision || {};
RiseVision.FinancialChart.DDEDataSource = {};

RiseVision.FinancialChart.DDEDataSource = function(url) {
    this.url = url;
    this.x = [];
    this.y = [];
    this.ticks = [];    
    this.volumeX = [];
    this.volumeY = [];
}
RiseVision.FinancialChart.DDEDataSource.prototype.load = function() {
    var self = this,
	settings = {
	url: prefs.getString("url"),
	refreshInterval: this.dayInterval,
	callback: function(data) {
	    self.data = data;
	    self.onDDEDataLoaded();
	    return data;
	}
    };
    
    getRawData(settings);
}
RiseVision.FinancialChart.DDEDataSource.prototype.onDDEDataLoaded = function(instrument) {
    for (var row = 0; row < numDataRows; row++) {
	//Instrument is in first column.
	if (this.data.getValue(row, 0) == instrument) {
	    this.ticks.push({
		"date": new Date(),
		"close": 0,
		"volume": 0
		//"date": new Date(result.data.getFormattedValue(row, 2)).getTime(),
		//"close": parseFloat(result.data.getFormattedValue(row, 0)),
		//"volume": parseInt(result.data.getFormattedValue(row, 1))
	    });
	    
	    this.x.push(row);
	    this.volumeX.push(row);
	    //this.y.push(parseFloat(this.data.getFormattedValue(row, 0)));		
	    //this.volumeY.push(parseFloat(this.data.getFormattedValue(row, 1)));
	}
    }
}